<?php

/**
 * Created by PhpStorm.
 * User: shwy
 * Date: 2017/7/21
 * Time: 11:55
 * 招投标管理
 */
class Bidding extends MY_Controller
{

    public function __construct()
    {
        parent::__construct();
        $this->load->model('bidding_model');
        $this->load->model('biddingcheck_model');
        $this->load->model('procurement_model');
        $this->load->model('supplier_model');
        $this->load->model('biddingwait_model', 'wait_model');
        $this->load->model('biddingwaitfile_model', 'waitFile_model');
        $this->load->model('user_model');
        $this->load->model('biddingconfirm_model');
        $this->load->model('check_model');
        $this->load->model('project_model');
        $this->load->library('Qiniu');
        $this->load->library('Sms');

    }

    //招投标项目列表页面
    public function index()
    {

//        $this->load->view('/admin/bidding/project/list');
//        echo 123123;
        $page_num = $this->config->item('fenye')['pageNum']; //每页的数据
        $start_position = ''; //初始数据
        $page = ($this->input->get('page')); //获取页码数量
        if (!$page) {
            $num = 1;
            $start_position = ($num - 1) * $page_num;
        } else {
            $start_position = ($page - 1) * $page_num;
        }


        //判断搜索内容是否存在存在就继续
        if ($this->input->get('search')) {
            $searchArg = [
                'field' => 'name',      //那个搜索
                'arg' => $this->input->get('search'), //搜索内容
                'side' => 'both'   //like通配符%的位置
            ];

            $data = $this->bidding_model->search('*', 0, $searchArg, $page_num, $start_position);

            foreach ($data[0] as $k => $v) {
                $arg = [
                    'needCode' => $v['needCode']
                ];
                $procurementData = $this->procurement_model->getByFieldQueryData('id,needCode', $arg, 1);

            }

            foreach ($data[0] as $k2 => $v2) {
                foreach ($procurementData as $k3 => $v3) {
                    if ($v2['needCode'] == $v3['needCode']) {
                        $data[0][$k2]['needId'] = $v3['id'];
                    }
                }
            }
            $viewData = [
                'list' => $data[0],  //这里得到从数据库中的当页数据
                'totalNum' => count($data['total_num']), //这里得到从数据库中的总页数
                'pageNum' => $page_num //每页显示多少条
            ];
            $this->load->view('/admin/bidding/project/list', $viewData);

        } else {
            //读取选了几个供应商 和 已上传的字段数量进行判断,如果一直status修改为5

            $data = $this->bidding_model->page('bidding', 0, $page_num, $start_position); //limit查询的数据

//            echo '<pre>';
//            print_r($data);
//            die();

            foreach ($data[0] as $k => $v) {
                //判断如果关联的需求单存在,就去查询
                if ($v['needCode']) {
                    $arg = [
                        'needCode' => $v['needCode']
                    ];
                    $procurementData[] = $this->procurement_model->getByFieldQueryData('id,needCode', $arg, 0);

                }

                $arg2 = [
                    'isEnd' => 1,
                    'biddingId' => $v['id']
                ];

                //确认完成的数量
                $data[0][$k]['completeNum'] = $this->wait_model->getByFieldQueryData('id,status,isEnd', $arg2, 1);

                //根据供应商id去查询待办表 = 5的,说明已经上传了资料,

                $supplierId[] = json_decode($v['supplierInfo'], true);

//                if($v['supplierNum'] = )
//
//                print_r($supplierNum);
//                die();
            }


            //判断是否结束
            foreach ($data[0] as $k2 => $v2) {
                if (isset($procurementData) && $procurementData) {
                    foreach ($procurementData as $k3 => $v3) {
                        if ($v2['needCode'] == $v3['needCode']) {
                            $data[0][$k2]['needId'] = $v3['id'];
                        }
                    }
                }


                //如果供应商完成数量跟所选供应商一直,就更新招标单的状态为 已完成

                //如果时间到了到期时间也表示结束
                if ($v2['supplierNum'] > 0 || time() > $v2['validDownTime']) {
                    __logInfo('a', $v2['id']);
                    if ((count($v2['completeNum']) == $v2['supplierNum']) || time() > $v2['validDownTime']) {

                        $biddingData = [
                            'status' => 2,
                            'isEnd' => 1
                        ];

                        $biddingWhere = [
                            'id' => $v2['id']
                        ];

//                        __logInfo('debug',$v2['id']);

                        $this->bidding_model->edit($biddingData, $biddingWhere);

                        if (!$v2['isEnd']) {
                            //防止冲突提交
                            //已完成之后新增到项目审核表
                            $checkAdd = [
                                'biddingId' => $v2['id'],
                                'code' => $v2['code'], //项目编码
                                'name' => $v2['name'],       //项目名称
                                'createTime' => $v2['createTime'], //发布时间
                                'address' => $v2['address'], //所在地区
                                'needCode' => $v2['needCode'], //需求单编号
                                'validTime' => $v2['validTime'], //有效时间
                                'projectImg' => $v2['projectImg'], //项目附件

                                'supplierInfo' => $v2['supplierInfo'], //供应商信息id,传json字符串
                                'supplierNum' => count(json_decode($v2['supplierInfo'], true)), //供应商数量

                                'synopsis' => $v2['synopsis'], //项目简介

                                //其他信息
                                'needData' => $v2['needData'],  //需要的资质数据,传json字符串
                                'needAmount' => $v2['needAmount'], //需要缴纳的保证金
                                'contactMan' => $v2['contactMan'], //联系人
                                'phone' => $v2['phone'],  //联系电话
                                'biddingFile' => $v2['biddingFile'],  //上传标书文件
                                'procurementImg' => $v2['procurementImg'],  //上传采购清单
                                'status' => 0
                            ];

                            $this->biddingcheck_model->add($checkAdd);

                        }


                    }
                }

            }


            if ($data) {
                $viewData = [
                    'list' => $data[0],  //这里得到从数据库中的当页数据
                    'totalNum' => $data['total_num'], //这里得到从数据库中的总页数
                    'pageNum' => $page_num //每页显示多少条

                ];
            } else {
                $viewData = [
                    'list' => $data[0],  //这里得到从数据库中的当页数据
                    'totalNum' => $data['total_num'], //这里得到从数据库中的总页数
                    'pageNum' => $page_num //每页显示多少条

                ];
            }


            $this->load->view('/admin/bidding/project/list', $viewData);
        }

    }

    //招投标项目新增功能
    public function addView()
    {
        //添加项目列表
        $data['project'] = $this->project_model->getData('id,name', 1);

        $this->load->view('/admin/bidding/project/add');
    }

    //招投标项目新增页面
    public function add()
    {
        // 上传文件，这里的pic是视图中file控件的name属性
//        $this->load->library('upload', __upload('bidding', 'bidding/project'));
//
//        $upload = 'upload';
//        $fileName = 'upload/bidding';
//        $pathName = 'upload/bidding/project';
//
//        if (!is_dir($upload)) {
//            mkdir($upload);
//        } else {
//            if (!is_dir($fileName)) {
//                mkdir($fileName);
//            } else {
//                if (!is_dir($pathName)) {
//                    mkdir($pathName);
//                }
//            }
//        }
        // 上传文件，这里的pic是视图中file控件的name属性

        //项目附件

        //报价确认单的地址
        if ($_FILES['projectImg']['error'] == 0) {
            $mime1 = substr($_FILES['projectImg']['name'], strrpos($_FILES['projectImg']['name'], '.')); //取得上传图片的后缀名

            $projectImgName = 'bidding/project/' . date('YmdHis') . rand(1000, 2000) . $mime1;  //新文件名

            $this->qiniu->upload($_FILES['projectImg']['tmp_name'], $projectImgName);
//        报价确认单的地址
            $projectImg = $this->config->item('qiniu')['url'] . $projectImgName;

            $projectImgOldName = $_FILES['projectImg']['name'];  //源文件名字
        } else {
            $projectImg = '';
            $projectImgOldName = '';
        }


        //标书文件
        if ($_FILES['biddingFile']['error'] == 0) {
            $mime2 = substr($_FILES['biddingFile']['name'], strrpos($_FILES['biddingFile']['name'], '.')); //取得上传图片的后缀名

            $biddingFileName = 'bidding/project/' . date('YmdHis') . rand(1000, 2000) . $mime2; //新文件名
            $this->qiniu->upload($_FILES['biddingFile']['tmp_name'], $biddingFileName);

            //报价确认单的地址
            $biddingFile = $this->config->item('qiniu')['url'] . $biddingFileName;

            $biddingFileOldName = $_FILES['biddingFile']['name'];  //源文件名字

        } else {
            $biddingFile = '';

            $biddingFileOldName = '';
        }


        //采购清单
        if ($_FILES['procurementImg']['error'] == 0) {
            $mime3 = substr($_FILES['procurementImg']['name'], strrpos($_FILES['procurementImg']['name'], '.')); //取得上传图片的后缀名

            $procurementImgName = 'bidding/project/' . date('YmdHis') . rand(1000, 2000) . $mime3; //新文件名
            $this->qiniu->upload($_FILES['procurementImg']['tmp_name'], $procurementImgName);

            $procurementImg = $this->config->item('qiniu')['url'] . $procurementImgName;

            $procurementOldName = $_FILES['procurementImg']['name'];  //源文件名字

        } else {
            $procurementImg = '';

            $procurementOldName = '';

        }


//        print_r($biddingFile);
//        die;

//        if (empty($projectImg)) {
//            unset($projectImg);
//        }

        $validTime = $_POST['validTime'];  //传过来的有效时间天数
        if (!isset($_POST['needData'])) {
            $_POST['needData'] = '';
        }
        //基本信息添加
        $baseInfo = [
            'code' => $_POST['code'], //项目编码
            'name' => $_POST['name'],       //项目名称
            'createTime' => strtotime($this->input->post('createTime')), //发布时间
            'address' => $_POST['address'], //所在地区
            'needCode' => $_POST['needCode'], //需求单编号
            'validDownTime' => strtotime(date("Y-m-d H:i:s", strtotime("+$validTime day"))), //倒计时有效时间
            'validTime' => $validTime, //有效时间
            'projectImg' => $projectImg, //项目附件

            'supplierInfo' => $_POST['supplierInfo'], //供应商信息id,传json字符串
            'supplierNum' => count(json_decode($_POST['supplierInfo'], true)), //供应商数量

            'synopsis' => $_POST['synopsis'], //项目简介

            //其他信息
            'needData' => $_POST['needData'],  //需要的资质数据,传json字符串
            'needAmount' => $_POST['needAmount'], //需要缴纳的保证金
            'contactMan' => $_POST['contactMan'], //联系人
            'phone' => $_POST['phone'],  //联系电话
            'biddingFile' => $biddingFile,  //上传标书文件
            'procurementImg' => $procurementImg,  //上传采购清单

            'projectImgOldName' => $projectImgOldName,
            'biddingFileOldName' => $biddingFileOldName,
            'procurementOldName' => $procurementOldName,
        ];

        if ($_POST['action'] == '暂存') {
            $baseInfo['status'] = 0;
        } else {
            $baseInfo['status'] = 1;
        }

//        //返回项目添加后的id
        $resultId = $this->bidding_model->addId($baseInfo);


        //当标书文件为真的时候，就新增到供应商代办的数据库中
        //此时并且检测，needCode是否存在，如果存在，就更新需求单的状态为5已完成。
        if ($baseInfo['status'] == 1) {
            if ($_POST['needCode']) {
                $proStatus = [
                    'status' => 5
                ];
                $proWhere = [
                    'needCode' => $_POST['needCode']
                ];

                $this->procurement_model->edit($proStatus, $proWhere);
            }


            $decodeSupplier = json_decode($_POST['supplierInfo'], true);
            foreach ($decodeSupplier as $k => $v) {
                $waitData = [
                    'biddingId' => $resultId,
                    'biddingCode' => $_POST['code'],
                    'name' => $_POST['name'],       //项目名称
                    'createTime' => trim(strtotime($this->input->post('createTime'))), //发布时间
                    'address' => $_POST['address'], //所在地区
                    'validTime' => $_POST['validTime'], //有效时间
                    'contactMan' => $_POST['contactMan'], //联系人
                    'needData' => $_POST['needData'],  //需要的资质数据,传json字符串
                    'supplierInfo' => $v,
                    'status' => 0,
                    'isEnd' => 0,//判断是否完成了
                    'needAmount' => $_POST['needAmount'] //需要缴纳的保证金
                ];

                $this->wait_model->add($waitData);

                $supplierId = [
                    'id' => $v
                ];
                $supplierPhone[] = $this->supplier_model->getByFieldQueryData('id,phone', $supplierId, 0);
            }


            // 退款成功之后，发送短信到供应商手机
            foreach ($supplierPhone as $v3) {
                $pars = array(
                    'name' => '供应商待办待办事项'
                );

                $res = $this->sms->run($v3['phone'], $this->config->item('aliyun_sms')['templateCode']['SMSTemplateCode'], $pars);
                if ($res) {
                    __logInfo('退款,短信发送成功', $v3['phone']);

                } else {
                    __logInfo('退款,短息发送失败', $v3['phone']);
                }
            }
        }


        $result = [
            'success' => 1
        ];

        echo json_encode($result, JSON_UNESCAPED_UNICODE);

    }

    //招投标项目编辑功能
    public function editView()
    {
        $arg = [
            'id' => $this->input->get('id')
        ];

        $data['list'] = $this->bidding_model->getByFieldQueryData('*', $arg, 0);

        //如果不存在直接跳转到404页面
        if (!$data['list']) {
            redirect('/home/error');
        }


        $data['list']['needData'] = json_decode($data['list']['needData'], true);

//        print_r(count(json_decode($data['list']['supplierInfo'], true)));
//        die();
        $data['list']['supplierInfo'] = json_decode($data['list']['supplierInfo'], true);

        if (count($data['list']['supplierInfo'])) {
            //取得所有的供应商id,并查询数据
            $supplierIds = $data['list']['supplierInfo'];
            foreach ($supplierIds as $k => $v) {
                $arg2 = [
                    'id' => $v
                ];

                $supplierData[] = $this->supplier_model->getByFieldQueryData('id,code,name,address,type', $arg2, 0);
            }
            $data['list']['supplierInfo'] = $supplierData;
        } else {
            unset($data['list']['supplierInfo']);
        }


//        echo '<pre>';
//        print_r($data);
//        die();

        $this->load->view('/admin/bidding/project/edit', $data);

    }

    //招投标项目编辑接口
    public function edit()
    {
        // 上传文件，这里的pic是视图中file控件的name属性
        //报价确认单的地址
        if ($_FILES['projectImg']['error'] == 0) {
            $mime1 = substr($_FILES['projectImg']['name'], strrpos($_FILES['projectImg']['name'], '.')); //取得上传图片的后缀名

            $projectImgName = 'bidding/project/' . date('YmdHis') . rand(1000, 2000) . $mime1;

            $this->qiniu->upload($_FILES['projectImg']['tmp_name'], $projectImgName);
//        报价确认单的地址
            $projectImg = $this->config->item('qiniu')['url'] . $projectImgName;

            $projectImgOldName = $_FILES['projectImg']['name'];  //源文件名字
        } else {
            $projectImg = '';

            $projectImgOldName = '';
        }


        //标书文件
        if ($_FILES['biddingFile']['error'] == 0) {
            $mime2 = substr($_FILES['biddingFile']['name'], strrpos($_FILES['biddingFile']['name'], '.')); //取得上传图片的后缀名

            $biddingFileName = 'bidding/project/' . date('YmdHis') . rand(1000, 2000) . $mime2;
            $this->qiniu->upload($_FILES['biddingFile']['tmp_name'], $biddingFileName);

            //报价确认单的地址
            $biddingFile = $this->config->item('qiniu')['url'] . $biddingFileName;

            $biddingFileOldName = $_FILES['biddingFile']['name'];  //源文件名字

        } else {
            $biddingFile = '';

            $biddingFileOldName = '';
        }


        //采购清单
        if ($_FILES['procurementImg']['error'] == 0) {
            $mime3 = substr($_FILES['procurementImg']['name'], strrpos($_FILES['procurementImg']['name'], '.')); //取得上传图片的后缀名

            $procurementImgName = 'bidding/project/' . date('YmdHis') . rand(1000, 2000) . $mime3;
            $this->qiniu->upload($_FILES['procurementImg']['tmp_name'], $procurementImgName);

            $procurementImg = $this->config->item('qiniu')['url'] . $procurementImgName;

            $procurementOldName = $_FILES['procurementImg']['name'];  //源文件名字

        } else {
            $procurementImg = '';

            $procurementOldName = '';
        }


        if (isset($_POST['needCode'])) {
            $needCode = $_POST['needCode'];
        } else {
            $needCode = '';
        }

        $arr = [];
        if (isset($_POST['needData'])) {
            $needData = $_POST['needData'];
        } else {
            $needData = json_encode($arr, JSON_UNESCAPED_UNICODE);
        }


        //基本信息
        $baseInfo = [
            'code' => $_POST['code'], //项目编码
            'name' => $_POST['name'],       //项目名称
            'createTime' => trim(strtotime($this->input->post('createTime'))), //发布时间
            'address' => $_POST['address'], //所在地区
            'needCode' => $needCode, //需求单编号
            'validTime' => $_POST['validTime'], //有效时间
            'projectImg' => $projectImg, //项目附件

            'supplierInfo' => $_POST['supplierInfo'], //供应商信息id,传json字符串
            'supplierNum' => count(json_decode($_POST['supplierInfo'], true)), //供应商数量

            'synopsis' => $_POST['synopsis'], //项目简介

            //其他信息
            'needData' => $needData,  //需要的资质数据,传json字符串
            'needAmount' => $_POST['needAmount'], //需要缴纳的保证金
            'contactMan' => $_POST['contactMan'], //联系人
            'phone' => $_POST['phone'],  //联系电话
            'biddingFile' => $biddingFile,  //上传标书文件
            'procurementImg' => $procurementImg,  //上传采购清单

            'projectImgOldName' => $projectImgOldName,
            'biddingFileOldName' => $biddingFileOldName,
            'procurementOldName' => $procurementOldName,

        ];

        __logInfo('asadasd', $_POST['supplierInfo']);
        if ($_POST['action'] == '暂存') {
            $baseInfo['status'] = 0;
        } else {
            $baseInfo['status'] = 1;

            //状态=1说明是提交, 并加入待办中, 此时更新供应商参数
            $decodeSupplier = json_decode($_POST['supplierInfo'], true);
            foreach ($decodeSupplier as $k => $v) {
                $waitData = [
                    'biddingId' => $_POST['id'],
                    'biddingCode' => $_POST['code'],
                    'name' => $_POST['name'],       //项目名称
                    'createTime' => trim(strtotime($this->input->post('createTime'))), //发布时间
                    'address' => $_POST['address'], //所在地区
                    'validTime' => $_POST['validTime'], //有效时间
                    'contactMan' => $_POST['contactMan'], //联系人
                    'needData' => $_POST['needData'],  //需要的资质数据,传json字符串
                    'supplierInfo' => $v,
                    'status' => 0,
                    'isEnd' => 0,//判断是否完成了
                    'needAmount' => $_POST['needAmount'] //需要缴纳的保证金
                ];

                $this->wait_model->add($waitData);

                $supplierId = [
                    'id' => $v
                ];
                $supplierPhone[] = $this->supplier_model->getByFieldQueryData('id,phone', $supplierId, 0);
            }


            // 退款成功之后，发送短信到供应商手机
            foreach ($supplierPhone as $v3) {
                $pars = array(
                    'name' => '供应商待办待办事项'
                );

                $res = $this->sms->run($v3['phone'], $this->config->item('aliyun_sms')['templateCode']['SMSTemplateCode'], $pars);
                if ($res) {
                    __logInfo('退款,短信发送成功', $v3['phone']);

                } else {
                    __logInfo('退款,短息发送失败', $v3['phone']);
                }
            }
        }


        if (empty($baseInfo['projectImg'])) {
            unset($baseInfo['projectImg']);
        }
        if (empty($baseInfo['biddingFile'])) {
            unset($baseInfo['biddingFile']);
        }
        if (empty($baseInfo['procurementImg'])) {
            unset($baseInfo['procurementImg']);
        }


        if (empty($baseInfo['projectImgOldName'])) {
            unset($baseInfo['projectImgOldName']);
        }
        if (empty($baseInfo['biddingFileOldName'])) {
            unset($baseInfo['biddingFileOldName']);
        }
        if (empty($baseInfo['procurementOldName'])) {
            unset($baseInfo['procurementOldName']);
        }

//        __logInfo('debug', json_encode($baseInfo, JSON_UNESCAPED_UNICODE));

        //用户id
        $where = [
            'id' => $_POST['id']
        ];

//        __logInfo('debug',json_encode($baseInfo,JSON_UNESCAPED_UNICODE));


//        __logInfo('debug',json_encode($where,JSON_UNESCAPED_UNICODE));


        //是否会有添加失败的情况?
        $this->bidding_model->edit($baseInfo, $where);

        $return = [
            'success' => 1
        ];

        echo json_encode($return);
    }

    //招投标项目详情页面
    public function detail()
    {
        $arg = [
            'id' => $this->input->get('id')
        ];

        $data['list'] = $this->bidding_model->getByFieldQueryData('*', $arg, 0);

        //如果不存在直接跳转到404页面
        if (!$data['list']) {
            redirect('/home/error');
        }


        $data['list']['needData'] = json_decode($data['list']['needData'], true);

//        print_r(count(json_decode($data['list']['supplierInfo'], true)));
//        die();
        $data['list']['supplierInfo'] = json_decode($data['list']['supplierInfo'], true);

        if (count($data['list']['supplierInfo'])) {
            //取得所有的供应商id,并查询数据
            $supplierIds = $data['list']['supplierInfo'];
            foreach ($supplierIds as $k => $v) {
                $arg2 = [
                    'id' => $v
                ];

                $supplierData[] = $this->supplier_model->getByFieldQueryData('id,code,name,address', $arg2, 0);
            }
            $data['list']['supplierInfo'] = $supplierData;
        } else {
            unset($data['list']['supplierInfo']);
        }

        //通过供应商id查询是否支付
        $arg3 = [
            'biddingId' => $this->input->get('id'),  //当前的标书id
            'supplierInfo' => $_COOKIE['supplierId'] //供应商id
        ];
        $supplierStatus = $this->wait_model->getByFieldQueryData('status', $arg3, 0);

        if ($supplierStatus['status'] == 2 || $supplierStatus['status'] == 5) {
            $data['list']['isPay'] = 1;
        } else {
            $data['list']['isPay'] = 0;
        }

//        echo '<pre>';
//        print_r($data);
//        die;

        $this->load->view('/admin/bidding/project/detail', $data);

    }


    //供应商代办列表页面
    public function waitIngList()
    {
        /*
        * 0为待处理      -->同意 拒绝
        * 1为待付保证金   -->去支付
        * 2为已支付  --> 上传资质
        * 3为已拒绝
        * 4为支付失败   -->重新支付
        * 5为已完成
        */

        //  140
        //根据当前供应商进来的id, 查询所包含此供应商的数据

        $page_num = $this->config->item('fenye')['pageNum']; //每页的数据
        $start_position = ''; //初始数据
        $page = ($this->input->get('page')); //获取页码数量
        if (!$page) {
            $num = 1;
            $start_position = ($num - 1) * $page_num;
        } else {
            $start_position = ($page - 1) * $page_num;
        }


        //判断搜索内容是否存在存在就继续
        if ($this->input->get('search')) {
            $searchArg = [
                'field' => 'name',      //那个搜索
                'arg' => $this->input->get('search'), //搜索内容
                'side' => 'both'   //like通配符%的位置
            ];

            $data = $this->wait_model->search('*', 0, $searchArg, $page_num, $start_position);

            foreach ($data[0] as $k => $v) {
                $arg = [
                    'needCode' => $v['needCode']
                ];
                $procurementData = $this->procurement_model->getByFieldQueryData('id,needCode', $arg, 1);

            }

            foreach ($data[0] as $k2 => $v2) {
                foreach ($procurementData as $k3 => $v3) {
                    if ($v2['needCode'] == $v3['needCode']) {
                        $data[0][$k2]['needId'] = $v3['id'];
                    }
                }
            }
            $viewData = [
                'list' => $data[0],  //这里得到从数据库中的当页数据
                'totalNum' => count($data['total_num']), //这里得到从数据库中的总页数
                'pageNum' => $page_num //每页显示多少条
            ];
            $this->load->view('/admin/bidding/waiting/list', $viewData);

        } else {

            //根据cookie id查询所包含的数据

            $where = [
                //todo 变成当前供应商id
                'supplierInfo' => isset($_COOKIE['supplierId']) ? $_COOKIE['supplierId'] : 0
//                'supplierInfo' => 3
            ];

            $data = $this->wait_model->page('biddingwait', $where, $page_num, $start_position); //limit查询的数据

//            echo '<pre>';
//            print_r($data);
//            die;

            //如果已支付status=2,就根据biddingId去查询bidding表的id查询标书文件
            foreach ($data[0] as $k => $v) {
                if ($v['status'] == 2) {
                    $ids[] = $v['biddingId'];  //管理的标书文件id
                }
            }
//            echo '<pre>';
//            print_r($ids);
//            die;
            if (isset($ids)) {
                foreach ($ids as $k2 => $v2) {
                    $arg = [
                        'id' => $v2
                    ];

                    $biddingFile[] = $this->bidding_model->getByFieldQueryData('id,code,biddingFile', $arg, 0);
                }
            }

//                    echo '<pre>';
//            print_r($biddingFile);
//            die;


            foreach ($data[0] as $k3 => $v3) {
                if (isset($biddingFile)) {
                    foreach ($biddingFile as $k4 => $v4) {
                        if ($v3['biddingId'] == $v4['id']) {
                            $data[0][$k3]['biddingFile'] = $v4['biddingFile'];
                        }
                    }
                }

            }


            if ($data) {
                $viewData = [
                    'list' => $data[0],  //这里得到从数据库中的当页数据
                    'totalNum' => $data['total_num'], //这里得到从数据库中的总页数
                    'pageNum' => $page_num //每页显示多少条

                ];
            } else {
                $viewData = [
                    'list' => $data[0],  //这里得到从数据库中的当页数据
                    'totalNum' => $data['total_num'], //这里得到从数据库中的总页数
                    'pageNum' => $page_num //每页显示多少条

                ];
            }

//            echo '<pre>';
//            print_r($data);
//             die();


            $this->load->view('/admin/bidding/waiting/list', $viewData);
        }

    }

    //同意功能
    public function agree()
    {
        //根据列表id,修改状态


        $data = [
            'status' => 1
        ];

        $where = [
            'id' => $_POST['id']
        ];

        $result = $this->wait_model->edit($data, $where);

        if ($result) {
            $result = [
                'success' => 1
            ];
        } else {
            $result = [
                'error' => 2
            ];
        }

        echo json_encode($result);
    }

    //拒绝功能,拒绝理由
    public function refuse()
    {
        //拒绝之后修改状态为status=3  并且isEnd = 1表示已完成
        $data = [
            'status' => 3,
            'refuseInfo' => $_POST['refuseInfo'],
            'isEnd' => 1
        ];

        $where = [
            'id' => $_POST['id']
        ];

        $result = $this->wait_model->edit($data, $where);

        if ($result) {
            $result = [
                'success' => 1
            ];
        } else {
            $result = [
                'error' => 2
            ];
        }


        echo json_encode($result);
    }


    //支付功能连通第三方接口
    private function pay()
    {

//     根据id去查询数据库中的supplierInfo   在通过supplierInfo查询供应商表中的   通联id

        echo 1231231213312123123;

    }

    //支付保证金页面
    public function payView()
    {

        //根据供应商待办id查询biddingId  ,  在根据biddingID查询 needAmount
        $arg = [
            'id' => $_GET['id']
        ];
        $biddingId = $this->wait_model->getByFieldQueryData('id,biddingId,supplierInfo', $arg, 0);  //查询关联的标书id

        $arg2 = [
            'id' => $biddingId['biddingId']
        ];
        $needAmount = $this->bidding_model->getByFieldQueryData('id,needAmount', $arg2, 0); //要支付的保证金


        $arg3 = [
            'id' => $biddingId['supplierInfo']
        ];
        $partnerUserId = $this->supplier_model->getByFieldQueryData('id,partnerUserId', $arg3, 0); //根据供应商id查询通联用户id

        $partner = $partnerUserId['partnerUserId'];  //精简化id
        $inputCharset = 1;
        $pickupUrl = 'http://118.89.161.43/admin/bidding/payResult';    //返回商户的地址
        $receiveUrl = 'http://118.89.161.43/admin/bidding/payResult';
        $version = 'v1.0';  //版本
        $signType = '0';    //
        $merchantId = '008330148163073';    //商务号
        $orderNo = 'NO' . date('YmdHis') . rand(1000, 9999);
//        $orderAmount= $needAmount['needAmount'];   //分为单位 10 = 1000
        $orderAmount = 1;   //todo 改为动态金额分为单位 10 = 1000
        $orderCurrency = '156';  //货币类型
        $orderDatetime = date('YmdHis');
        $ext1 = "<USER>$partner</USER>";   //用户名
        $payType = 33;    //支付方式
        $key = 1234567890;    //加密key
//print_r($needAmount);
//die();
        $bufSignSrc = "";
        if ($inputCharset != "")
            $bufSignSrc = $bufSignSrc . "inputCharset=" . $inputCharset . "&";
        if ($pickupUrl != "")
            $bufSignSrc = $bufSignSrc . "pickupUrl=" . $pickupUrl . "&";
        if ($receiveUrl != "")
            $bufSignSrc = $bufSignSrc . "receiveUrl=" . $receiveUrl . "&";
        if ($version != "")
            $bufSignSrc = $bufSignSrc . "version=" . $version . "&";
        if ($signType != "")
            $bufSignSrc = $bufSignSrc . "signType=" . $signType . "&";
        if ($merchantId != "")
            $bufSignSrc = $bufSignSrc . "merchantId=" . $merchantId . "&";

        if ($orderNo != "")
            $bufSignSrc = $bufSignSrc . "orderNo=" . $orderNo . "&";
        if ($orderAmount != "")
            $bufSignSrc = $bufSignSrc . "orderAmount=" . $orderAmount . "&";
        if ($orderCurrency != "")
            $bufSignSrc = $bufSignSrc . "orderCurrency=" . $orderCurrency . "&";
        if ($orderDatetime != "")
            $bufSignSrc = $bufSignSrc . "orderDatetime=" . $orderDatetime . "&";
        if ($ext1 != "")
            $bufSignSrc = $bufSignSrc . "ext1=" . $ext1 . "&";
        if ($payType != "")
            $bufSignSrc = $bufSignSrc . "payType=" . $payType . "&";


        $bufSignSrc = $bufSignSrc . "key=" . $key; //key为MD5密钥，密钥是在通联支付网关商户服务网站上设置。

//        echo $bufSignSrc;
//        die();

        //签名，设为signMsg字段值。
        $signMsg = strtoupper(md5(trim($bufSignSrc)));


        $data = [
            'inputCharset' => $inputCharset,
            'pickupUrl' => $pickupUrl,  //取货地址
            'receiveUrl' => $receiveUrl,  //商务系统通知地址
            'version' => $version,
            'signType' => $signType,
            'merchantId' => $merchantId,
            'orderNo' => $orderNo,
            'orderAmount' => $orderAmount,  //金额
            'orderCurrency' => $orderCurrency,
            'orderDatetime' => $orderDatetime,
            'ext1' => $ext1,
            'payType' => $payType,
            'signMsg' => $signMsg,

            //自定义参数
            'needAmount' => $needAmount['needAmount']
        ];


        $this->load->view('/admin/bidding/waiting/pay', $data);
    }

    //支付结果页面
    public function payResult()
    {
        $this->load->view('/admin/bidding/waiting/payResult');
    }

    //支付的时候编辑供应商的订单号和订单时间接口
    public function editWaitOrderNo()
    {

        $data = [
            'orderNo' => $_POST['orderNo'],  //订单号
            'orderDatetime' => $_POST['orderDatetime'], //订单时间
            'needAmount' => $_POST['needAmount'] //退款金额
        ];

        $where = [
            'id' => $_POST['id']
        ];

        $this->wait_model->edit($data, $where);
    }

    //支付成功之后回调地址修改供应的信息接口
    public function editWaitStatus()
    {

        if ($_POST['status'] == 2) {
            $data = [
                'status' => $_POST['status'],
            ];
        } else {
            $data = [
                'status' => $_POST['status'],
            ];
        }


        $arg = [
            'orderNo' => $_POST['orderNo']
        ];

        $waitId = $this->wait_model->getByFieldQueryData('id', $arg, 0);  //查询关联的标书id


        $where = [
            'id' => $waitId['id']
        ];

        $this->wait_model->edit($data, $where);

    }

    /**
     * 资质上传功能
     * 6个文件上传参数
     * 2个字段
     * biddingId招投标的id
     */
    public function dataUpload()
    {
        //上传投标文件
        if ($_FILES['biddingFile']['error'] == 0) {
            $mime1 = substr($_FILES['biddingFile']['name'], strrpos($_FILES['biddingFile']['name'], '.')); //取得上传图片的后缀名

            $biddingFileName = 'bidding/qualification/' . date('YmdHis') . rand(1000, 2000) . $mime1;

            $this->qiniu->upload($_FILES['biddingFile']['tmp_name'], $biddingFileName);
//        报价确认单的地址
            $biddingFile = $this->config->item('qiniu')['url'] . $biddingFileName;
        } else {
            $biddingFile = '';
        }


        //上传报价单
        if ($_FILES['bjFile']['error'] == 0) {
            $mime2 = substr($_FILES['bjFile']['name'], strrpos($_FILES['bjFile']['name'], '.')); //取得上传图片的后缀名

            $bjFileName = 'bidding/qualification/' . date('YmdHis') . rand(1000, 2000) . $mime2;
            $this->qiniu->upload($_FILES['bjFile']['tmp_name'], $bjFileName);

            //报价确认单的地址
            $bjFile = $this->config->item('qiniu')['url'] . $bjFileName;

        } else {
            $bjFile = '';
        }


        //营业执照
        if ($_FILES['yyzzFile']['error'] == 0) {
            $mime3 = substr($_FILES['yyzzFile']['name'], strrpos($_FILES['yyzzFile']['name'], '.')); //取得上传图片的后缀名

            $yyzzFileName = 'bidding/qualification/' . date('YmdHis') . rand(1000, 2000) . $mime3;
            $this->qiniu->upload($_FILES['yyzzFile']['tmp_name'], $yyzzFileName);

            $yyzzFile = $this->config->item('qiniu')['url'] . $yyzzFileName;

        } else {
            $yyzzFile = '';
        }

        //其他资质
        if ($_FILES['otherFile']['error'] == 0) {
            $mime4 = substr($_FILES['otherFile']['name'], strrpos($_FILES['otherFile']['name'], '.')); //取得上传图片的后缀名

            $otherFileName = 'bidding/qualification/' . date('YmdHis') . rand(1000, 2000) . $mime4;
            $this->qiniu->upload($_FILES['otherFile']['tmp_name'], $otherFileName);

            $otherFile = $this->config->item('qiniu')['url'] . $otherFileName;

        } else {
            $otherFile = '';
        }


        //资质上传数据
        $data = [
            'contactMan' => $_POST['contactMan'], //联系人
            'phone' => $_POST['phone'],             //联系电话
            'supplierInfo' => isset($_COOKIE['supplierId']) ? $_COOKIE['supplierId'] : 0,    //todo 当前供应商id
            'biddingWaitId' => $_POST['biddingId'],   // 跟换修改为标书biddingId

            'biddingFile' => $biddingFile,
            'bjFile' => $bjFile,
            'yyzzFile' => $yyzzFile,
            'otherFile' => $otherFile,
            'createTime' => time(),
            'status' => 1
        ];

        $result = $this->waitFile_model->add($data);

        if ($result) {
            //资质上传成功之后,状态变成已上传并完成
            $biddingData = [
                'status' => 5,
                'isEnd' => 1
            ];
            $where = [
                'id' => $_GET['id'] //关联的供应商待办的id
            ];

            //更新供应商待办里面的状态
            $this->wait_model->edit($biddingData, $where);
        }


        //资质上传成功之后修改状态为status=5  并且isEnd = 1表示已完成
        $waitData = [
            'status' => 5,
            'isEnd' => 1
        ];

        $waitWhere = [
            'id' => $_POST['id']
        ];
        $this->wait_model->edit($waitData, $waitWhere);


        redirect('/admin/bidding/waitingList?page=1');

    }

    //资质上传页面
    public function dataUploadView()
    {

        $arg = [
            'id' => $_GET['id']
        ];

        //根据id读取所需要上传的资质,
        /*Array
        (
            [id] => 2
            [needData] => ["组织结构","营业执照"]
        )
        */
        $data['list'] = $this->wait_model->getByFieldQueryData('id,needData', $arg, 0);

        //如果不存在直接跳转到404页面
        if (!$data['list']) {
            redirect('/home/error');
        }


        $this->load->view('/admin/bidding/waiting/dataUpload', $data);

    }


    //审核列表页面
    public function checkList()
    {

//        $this->load->view('/admin/bidding/project/list');
//        echo 123123;
        $page_num = $this->config->item('fenye')['pageNum']; //每页的数据
        $start_position = ''; //初始数据
        $page = ($this->input->get('page')); //获取页码数量
        if (!$page) {
            $num = 1;
            $start_position = ($num - 1) * $page_num;
        } else {
            $start_position = ($page - 1) * $page_num;
        }


        //判断搜索内容是否存在存在就继续
        if ($this->input->get('search')) {
            $searchArg = [
                'field' => 'name',      //那个搜索
                'arg' => $this->input->get('search'), //搜索内容
                'side' => 'both'   //like通配符%的位置
            ];

            $data = $this->biddingcheck_model->search('*', 0, $searchArg, $page_num, $start_position);

            foreach ($data[0] as $k => $v) {
                $arg = [
                    'needCode' => $v['needCode']
                ];
                $procurementData = $this->procurement_model->getByFieldQueryData('id,needCode', $arg, 1);

            }

            foreach ($data[0] as $k2 => $v2) {
                foreach ($procurementData as $k3 => $v3) {
                    if ($v2['needCode'] == $v3['needCode']) {
                        $data[0][$k2]['needId'] = $v3['id'];
                    }
                }
            }
            $viewData = [
                'list' => $data[0],  //这里得到从数据库中的当页数据
                'totalNum' => count($data['total_num']), //这里得到从数据库中的总页数
                'pageNum' => $page_num //每页显示多少条
            ];
            $this->load->view('/admin/bidding/check/list', $viewData);

        } else {
            //读取选了几个供应商 和 已上传的字段数量进行判断,如果一直status修改为5

            $data = $this->biddingcheck_model->page('biddingcheck', 0, $page_num, $start_position); //limit查询的数据
//            echo '<pre>';
//            print_r($data);
//            die();

//            echo '<pre>';
//            print_r($data);
//            die;
//
            foreach ($data[0] as $k => $v) {
                $arg = [
                    'needCode' => $v['needCode']
                ];
                $procurementData[] = $this->procurement_model->getByFieldQueryData('id,needCode', $arg, 0);


                //查询有效的供应商信息
                //根据当前标书id和供应商id去查询文件表是否存在,如果存在就说明有
                $supplierIds[$v['biddingId']] = json_decode($v['supplierInfo'], true);


//
////                print_r($supplierIds);
////                die;
//                foreach ($supplierIds as $k2 => $v2) {
//                    $arg2 = [
//                        'id' => $v2
//                    ];
//
//                    $supplierData[] = $this->supplier_model->getByFieldQueryData('id,code,name,address,offerNum', $arg2, 0);
//                }
//                $checkInfoData2['supplierInfo'] = $supplierData;
//                //只显示上传资料的供应商
//                foreach ($checkInfoData2['supplierInfo'] as $k3 => $v3) {
//                    //根据供应商id查询供应商文件表是否有数据,有数据就显示,没数据就不显示
//                    $arg3 = [
//                        'supplierInfo' => $v3['id'],
////                        'biddingWaitId' =>
//                    ];
//
//                    $supplierFile[] = $this->waitFile_model->getByFieldQueryData('id,biddingWaitId', $arg3, 0);
//                }

//                foreach ($checkInfoData2['supplierInfo'] as $k4 => $v4) {
//                    foreach ($supplierFile as $k5 => $v5) {
//                        //查询不到id,则删除当前的供应商信息
//                        if (!count($v5)) {
//                            unset($checkInfoData2['supplierInfo'][$k5]);
//                        }
//                    }
//                }
//
//                $data[0][$k]['validSupplierNum'] = count($checkInfoData2['supplierInfo']);  //有效的供应商数量
            }

//            echo '<pre>';
//            print_r($supplierIds);
//            die();
//

            if (isset($supplierIds) && $supplierIds) {
                foreach ($supplierIds as $k2 => $v2) {
                    //根据供应商id查询供应商文件表是否有数据,有数据就显示,没数据就不显示
                    if ($v2) {
                        foreach ($v2 as $k3 => $v3) {
                            $arg3 = [
                                'supplierInfo' => $v3,
                                'biddingWaitId' => $k2
                            ];

                            $supplierFile[] = $this->waitFile_model->getByFieldQueryData('id,biddingWaitId', $arg3, 0);
                        }
                    }

                }
            }


//            echo '<pre>';
//            print_r($supplierFile);
//            die();

            foreach ($data[0] as $k4 => $v4) {
                if (isset($supplierFile) && $supplierFile) {
                    foreach ($supplierFile as $k5 => $v5) {
                        if ($v4['biddingId'] == $v5['biddingWaitId']) {
                            $data[0][$k4]['validSupplier'][] = $v5['id'];  //文件表的id
                        }
                    }
                }
            }

//            $data[0][0]['validSupplier'][1] = 222;
//
//            echo '<pre>';
//            print_r($data[0]);
//            die();
//

//            echo '<pre>';
//            print_r($procurementData);
//            die();

            foreach ($data[0] as $k6 => $v6) {
                if (isset($procurementData)) {
                    foreach ($procurementData as $k7 => $v7) {
                        if ($v6['needCode'] == $v7['needCode']) {
                            $data[0][$k6]['needId'] = $v7['id'];
                            break;
                        } else {
                            $data[0][$k6]['needId'] = '';
                        }
                    }
                }


                //插叙已审核人员的信息
                //统计数量,如果相同就修改状态为已完成
                //如果评分在count等于评委人数 就修改状态为评审完成


                //有效供应商数量 * 选择的评审人 == checkinfo数量
                //2 * 4 = 8  c
                //如果已经接触了,就不加入到定标数据库中了


                if (!$v6['isEnd']) {
                    $countPeople = count(json_decode($v6['checkPeople'], true));  //审核人员数
                    $countCheckInfo = count(json_decode($v6['checkInfo'], true));  //审核人员信息
                    if (isset($v6['validSupplier']) && $v6['validSupplier']) {
                        $countValidSupplier = count($v6['validSupplier']);  //有效的供应商数量
                    } else {
                        $countValidSupplier = 0; //判断变量是否存在，不存在就为0
                    }

                    __logInfo('checkPeople', $countPeople);
                    __logInfo('checkInfo', $countCheckInfo);

                    __logInfo('validSupplierNum', $countValidSupplier);

                    if ($countPeople > 0 || $countValidSupplier > 0) {
                        $num = $countPeople * $countValidSupplier;

                        __logInfo('a', 123123);

                        // checkInfo 确定完成
//                        __logInfo('num',$num);
//                        __logInfo('asdasd',)
                        if ($num > 0 && $v6['checkInfo']) {
                            __logInfo('$num', $num);
                            __logInfo('$countCheckInfo', $countCheckInfo);

                            if ($num == $countCheckInfo) {

                                $editData = [
                                    'status' => 2,
                                    'isEnd' => 1
                                ];
                                $editWhere = [
                                    'id' => $v6['id']
                                ];

//                            __logInfo('a',$editWhere);
                                $this->biddingcheck_model->edit($editData, $editWhere);


                                //新增到项目定标列表
                                $confirmData = [
                                    'code' => $v6['code'],
                                    'name' => $v6['name'],
                                    'createTime' => $v6['createTime'],
                                    'needAmount' => $v6['needAmount'],
                                    'address' => $v6['address'],
                                    'relevanceId' => $v6['id'],  //已审批完成的数据id , 标书id
                                    'status' => 0,
                                    'isEnd' => 0,
                                ];


                                $this->biddingconfirm_model->add($confirmData);
                            }
                        }

                    }


                }

            }


//            echo '<pre>';
//            print_r($data);
//            die;


            if ($data) {
                $viewData = [
                    'list' => $data[0],  //这里得到从数据库中的当页数据
                    'totalNum' => $data['total_num'], //这里得到从数据库中的总页数
                    'pageNum' => $page_num //每页显示多少条

                ];
            } else {
                $viewData = [
                    'list' => $data[0],  //这里得到从数据库中的当页数据
                    'totalNum' => $data['total_num'], //这里得到从数据库中的总页数
                    'pageNum' => $page_num //每页显示多少条

                ];
            }


//            echo '<pre>';
//            print_r($data[0]);
//            die();


            $this->load->view('/admin/bidding/check/list', $viewData);
        }

    }

    //审核详情页面
    public function checkDetail()
    {
        $arg = [
            'id' => $_GET['id']
        ];
        $data['list'] = $this->biddingcheck_model->getByFieldQueryData('*', $arg, 0);

//        echo '<pre>';
//        print_r($data['list']);
//        die;

        //如果不存在直接跳转到404页面
        if (!$data['list']) {
            redirect('/home/error');
        }


        $arg2 = [
            'isEnd' => 1,
            'biddingId' => $data['list']['biddingId']
        ];

        //根据id读取
        $waitStatus = $this->wait_model->getByFieldQueryData('status', $arg2, 1);

        $arg3 = [
            'biddingWaitId' => $data['list']['biddingId']
        ];
        $data['list']['waitFile'] = $this->waitFile_model->getByFieldQueryData('id,contactMan,phone,bjFile,yyzzFile,otherFile', $arg3, 0); //供应商上传到的文件


        $status = array_column($waitStatus, 'status');

//        echo '<pre>';
//        print_r($status);
//        die();

        $supplierIds = json_decode($data['list']['supplierInfo'], true);

        foreach ($supplierIds as $k => $v) {
            $arg2 = [
                'id' => $v
            ];

            $supplierData[] = $this->supplier_model->getByFieldQueryData('id,code,name,address,offerNum', $arg2, 0);
        }
        $data['list']['supplierInfo'] = $supplierData;
        $data['list']['supplierInfoAll'] = $supplierData;


        //只显示上传资料的供应商
        foreach ($data['list']['supplierInfo'] as $k2 => $v2) {
            //根据供应商id查询供应商文件表是否有数据,有数据就显示,没数据就不显示
            $arg3 = [
                'supplierInfo' => $v2['id']
            ];

            $supplierFile[] = $this->waitFile_model->getByFieldQueryData('id', $arg3, 0);
        }

        foreach ($data['list']['supplierInfo'] as $k3 => $v3) {
            foreach ($supplierFile as $k4 => $v4) {
                //查询不到id,则删除当前的供应商信息
                if (!count($v4)) {
                    unset($data['list']['supplierInfo'][$k4]);
                }
            }
        }


        //todo 预选供应商换成$list['supplierNum']


//        echo '<pre>';
//        print_r($data);
//        die();


// Array
//        (
//            [5] => 2
//    [3] => 1
//)
        //判断3拒绝
        //5已同意的数据
        $repeat = array_count_values($status);

//        print_r($repeat);
//        die();


        $data['list']['agree'] = isset($repeat[5]) ? $repeat[5] : 0;
        $data['list']['refuse'] = isset($repeat[3]) ? $repeat[3] : 0;

        //todo 营业执照和其他文件查询

//        echo '<pre>';
//        print_r($data);
//        die();


        $this->load->view('/admin/bidding/check/detail', $data);
    }

    //审核详情页面
    public function checkEditView()
    {
        $arg = [
            'id' => $_GET['id']
        ];
        $data['list'] = $this->biddingcheck_model->getByFieldQueryData('*', $arg, 0);

        //如果不存在直接跳转到404页面
        if (!$data['list']) {
            redirect('/home/error');
        }

        //根据审核库里面的id查询关联的code,在查询出来状态
        $arg2 = [
            'isEnd' => 1,
            'biddingCode' => $data['list']['code']   //审核管理id
        ];

        //根据id读取
        $waitStatus = $this->wait_model->getByFieldQueryData('status', $arg2, 1);

        $status = array_column($waitStatus, 'status');

        // Array
//        (
//            [5] => 2
//    [3] => 1
//)
        //判断3拒绝
        //5已同意的数据
        if ($status) {
            $repeat = array_count_values($status);
        } else {
            $repeat = '';
        }
        $data['list']['agree'] = isset($repeat[5]) ? $repeat[5] : 0;
        $data['list']['refuse'] = isset($repeat[3]) ? $repeat[3] : 0;

        //        echo '<pre>';
//        print_r($status);
//        die();

        $supplierIds = json_decode($data['list']['supplierInfo'], true);

        //todo 是否需要不存在直接返回404页面
//            if(!$supplierIds){
//                redirect('/home/error');
//            }

//        print_r($supplierIds);
//        die();

        foreach ($supplierIds as $k => $v) {
            $arg2 = [
                'id' => $v
            ];

            $supplierData[] = $this->supplier_model->getByFieldQueryData('id,code,name,address,offerNum', $arg2, 0);
        }

//        print_r($supplierData);
//        die();
        $data['list']['supplierInfoAll'] = $supplierData;
        $data['list']['supplierInfo'] = $supplierData;

//        echo '<pre>';
//        print_r($data['list']['supplierInfo']);
//        die;


        //只显示上传资料的供应商
        foreach ($data['list']['supplierInfo'] as $k2 => $v2) {
            //根据供应商id查询供应商文件表是否有数据,有数据就显示,没数据就不显示
            $arg3 = [
                'supplierInfo' => $v2['id']
            ];

            $supplierFile[] = $this->waitFile_model->getByFieldQueryData('id', $arg3, 0);
        }

//        echo '<pre>';
//        print_r($supplierFile);
//        die();


        foreach ($data['list']['supplierInfo'] as $k3 => $v3) {
            foreach ($supplierFile as $k4 => $v4) {
                //查询不到id,则删除当前的供应商信息
                if (!count($v4)) {
                    unset($data['list']['supplierInfo'][$k4]);
                }
            }
        }


//        print_r($repeat);
//        die();


//        echo '<pre>';
//        print_r($data);
//        die();


        $this->load->view('/admin/bidding/check/edit', $data);
    }

    //选择评审接口
    public function choose()
    {
        $page_num = $this->config->item('fenye')['pageNum']; //每页的数据
        $start_position = ''; //初始数据
        $page = $_POST['page']; //获取页码数量
        if (!$page) {
            $num = 1;
            $start_position = ($num - 1) * $page_num;
        } else {
            $start_position = ($page - 1) * $page_num;
        }


        $arg = $_POST['type'];  //判断是招标评审员还是定标评审员
        $result = $this->user_model->FindInSetLimit($arg, $start_position, $page_num);

        $result['pageNum'] = $page_num;


        echo json_encode($result, JSON_UNESCAPED_UNICODE);
    }

    //确定评委接口
    public function confirmPeople()
    {
        //数据库存入该条信息谁是评委
        $data = [
            'status' => 1,
            'isEnd' => 0,
            'checkPeople' => $_POST['checkPeople'] //name json字符串
        ];
        $where = [
            'id' => $_POST['id']
        ];
        $this->biddingcheck_model->edit($data, $where);

        $user = json_decode($_POST['checkPeople'], true);

        foreach ($user as $k => $v) {
            //同时向审核数据库中存入招投标项目数据
            $checkData = [
                'type' => 2,
                'relevanceId' => $_POST['id'],
                'checkinfo' => '',
                'checker' => $v,
                'status' => 0,
                'checkStatus' => 0,
                'howLevelCheck' => 0,
                'createTime' => time(),
                'checkOrderType' => '招标项目评审'
            ];

            $this->check_model->add($checkData);
        }

        if ($user) {
            $result = [
                'success' => 1
            ];
        } else {
            $result = [
                'success' => 1
            ];
        }

        echo json_encode($result);

    }

    //根据供应商id选择不同的资质资料接口
    public function chooseSupplierFile()
    {

        //根据审核id查询出来标书id,
        $arg = [
            'id' => $_POST['biddingCheckId']   //供应商审核表的id
        ];
        $biddingId = $this->biddingcheck_model->getByFieldQueryData('id,biddingId,checkInfo', $arg, 0);
        $biddingId['checkInfo'] = json_decode($biddingId['checkInfo'], true);

//        print_r($biddingId['checkInfo']);
//         die;
//

        //再根据供应商待办id和供应商id,查询供应商文件id.
        $arg3 = [
            'biddingWaitId' => $biddingId['biddingId'],  //标书id
            'supplierInfo' => $_POST['supplierId']  //供应商id
        ];


        $waitFile = $this->waitFile_model->getByFieldQueryData('*', $arg3, 0);
        if ($biddingId['checkInfo']) {

            foreach ($biddingId['checkInfo'] as $k => $v) {
                //添加判断条件,如果checkUser不等于当前用户,则删除
                if ($v['supplierId'] != $_POST['supplierId'] || $v['checkUser'] != $_COOKIE['nickname']) {
                    unset($biddingId['checkInfo'][$k]);
                }
            }

            sort($biddingId['checkInfo']);
        }

        $waitFile['score'] = $biddingId['checkInfo'];
        $arg4 = [
            'id' => $_POST['supplierId']  //供应商di
        ];
        $offerNum = $this->supplier_model->getByFieldQueryData('offerNum', $arg4, 0);

        $waitFile['offerNum'] = $offerNum['offerNum'];  //评分系数


        //根据标书id和供应商id查询拒绝理由
        $arg4 = [
            'biddingId' => $biddingId['biddingId'],  //标书id
            'supplierInfo' => $_POST['supplierId'],  //供应商id
            'status' => 3
        ];

        $refuseInfo = $this->wait_model->getByFieldQueryData('id,refuseInfo', $arg4, 0);
        $waitFile['refuseInfo'] = $refuseInfo['refuseInfo']; //供应商拒绝信息


        //根据供应商id
//        $arg = [
//            'biddingWaitId' => $_POST['biddingWaitId'],  //标书id
//            'supplierInfo' => $_POST['supplierId']
//        ];
//
//
//        $supplierData = $this->waitFile_model->getByFieldQueryData('*', $arg, 0);
//
//        $arg2 = [
//            'id' => $_POST['supplierId']  //供应商di
//        ];
//        $offerNum = $this->supplier_model->getByFieldQueryData('offerNum', $arg2, 0);
//
//        $supplierData['offerNum'] = $offerNum['offerNum'];

//        print_r($offerNum);
//        die();


        echo json_encode($waitFile, JSON_UNESCAPED_UNICODE);
    }

    //评分接口
    public function score()
    {
        $arg = [
            'id' => $_POST['id']  //审核表的id
        ];
        $checkInfoData = $this->biddingcheck_model->getByFieldQueryData('id,supplierInfo,checkInfo', $arg, 0);


        $score = json_decode($_POST['score'], true);
//        [{"supplierId":3,"score":87,"checkUser":"管理员","supplierName":"苏州三维"},{"supplierId":1,"score":90,"checkUser":"管理员","supplierName":"铭展科技"}]
//        $score = [
//            0 => [
//                'supplierId' => 3,
//                'score' => 6363636,
//                'checkUser' => '管理员123123',
//                'supplierName' => '苏州三维'
//            ],
//            1 => [
//                'supplierId' => 1,
//                'score' => 9999999,
//                'checkUser' => '管理员123123',
//                'supplierName' => '铭展科技'
//            ],
//        ];

        //如果checkInfo为空直接写入
        if (empty($checkInfoData['checkInfo'])) {
            $data = [
                'checkInfo' => json_encode($score, JSON_UNESCAPED_UNICODE)
            ];
        } else {
            //如果不为空,就判断checkUser是否存在,如果存在就删除当前的数组,并加入新的
            $checkInfoData['checkInfo'] = json_decode($checkInfoData['checkInfo'], true);
            foreach ($checkInfoData['checkInfo'] as $k5 => $v5) {
                foreach ($score as $k4 => $v4) {
                    if ($v4['checkUser'] == $v5['checkUser']) {
                        unset($checkInfoData['checkInfo'][$k5]);
                        @array_push($score, $checkInfoData['checkInfo'][$k5]);
                        break;
                    } else {

                        @array_push($score, $v5);
                        break;
                    }
                }
            }
            $score = array_filter($score); //去除字符串为空的值
            $data = [
                'checkInfo' => json_encode($score, JSON_UNESCAPED_UNICODE)
            ];

        }
        $this->biddingcheck_model->edit($data, $arg);
//        die;


        /*
            第一次如果checkInfo为空直接写入:
                [{"supplierId":"3","score":87,"checkUser":"管理员","supplierName":"苏州三维"},
                {"supplierId":"1","score":90,"checkUser":"管理员","supplierName":"铭展科技"}]

            如果不为空,判断checkUser是否存在,如果checkUser存在unset当前数组,并且此时checkInfo还是有值的,就push到尾后


                    如果不存在,则直接push数组尾后

        */
//        print_r($checkInfoData);
//        die;


        //编辑完成之后,再去查询一遍数据库中的信息
        $checkInfoData2 = $this->biddingcheck_model->getByFieldQueryData('id,supplierInfo,checkInfo', $arg, 0);

        //查询有效的供应商信息
        $supplierIds = json_decode($checkInfoData2['supplierInfo'], true);
        foreach ($supplierIds as $k => $v) {
            $arg2 = [
                'id' => $v
            ];

            $supplierData[] = $this->supplier_model->getByFieldQueryData('id,code,name,address,offerNum', $arg2, 0);
        }
        $checkInfoData2['supplierInfo'] = $supplierData;
        //只显示上传资料的供应商
        foreach ($checkInfoData2['supplierInfo'] as $k2 => $v2) {
            //根据供应商id查询供应商文件表是否有数据,有数据就显示,没数据就不显示
            $arg3 = [
                'supplierInfo' => $v2['id']
            ];

            $supplierFile[] = $this->waitFile_model->getByFieldQueryData('id', $arg3, 0);
        }

        foreach ($checkInfoData2['supplierInfo'] as $k3 => $v3) {
            foreach ($supplierFile as $k4 => $v4) {
                //查询不到id,则删除当前的供应商信息
                if (!count($v4)) {
                    unset($checkInfoData2['supplierInfo'][$k4]);  //有效的供应商数量
                }
            }
        }

        $formatCheckInfo = json_decode($checkInfoData2['checkInfo'], true);
        //判断如果$formatCheckInfo  中的 checkUser 相同总数 等于 有效的供应商数量  则就编辑审核列表里面当前审核id的状态为已评分
        $i = 0;
        foreach ($formatCheckInfo as $k5 => $v5) {
            //项目评分接口 用户名变成动态
            $arr = $_COOKIE['nickname'];
            if ($v5['checkUser'] == $arr && $v5['score']) {
                $i++;
            }
        }

//        print_r($i);
//        print_r(count($checkInfoData2['supplierInfo']));
//        die;

        if ($i == count($checkInfoData2['supplierInfo'])) {
            $checkData = [
                'status' => 1  //已评分
            ];
            $checkWhere = [
                'id' => $_POST['checkId']  //审核管理id
            ];
            $checkEdit = $this->check_model->edit($checkData, $checkWhere);

            if ($checkEdit) {
                $result = [
                    'success' => 1
                ];
            } else {
                $result = [
                    'error' => 000
                ];
            }

            echo json_encode($result);
        } else {

            //还没评分结束,返回
            $result = [
                'success' => 1
            ];

            echo json_encode($result);
        }
    }


    //项目定标列表页面
    public function confirmList()
    {

//        $this->load->view('/admin/bidding/project/list');
//        echo 123123;
        $page_num = $this->config->item('fenye')['pageNum']; //每页的数据
        $start_position = ''; //初始数据
        $page = ($this->input->get('page')); //获取页码数量
        if (!$page) {
            $num = 1;
            $start_position = ($num - 1) * $page_num;
        } else {
            $start_position = ($page - 1) * $page_num;
        }


        //判断搜索内容是否存在存在就继续

        //读取选了几个供应商 和 已上传的字段数量进行判断,如果一直status修改为5

        $data = $this->biddingconfirm_model->page('biddingconfirm', 0, $page_num, $start_position); //limit查询的数据

        // echo '<pre>';
        // print_r($data);
        // die();
        if ($data[0]) {
            foreach ($data[0] as $k => $v) {

                $arg = [
                    'id' => $v['relevanceId'],
                    'isEnd' => 1
                ];

                $field = 'id,biddingId,code,needCode,name,createTime,validTime,address,contactMan';
                $biddinfCheckInfo[] = $this->biddingcheck_model->getByFieldQueryData($field, $arg, 0);

            }

//             echo '<pre>';
//             print_r($biddinfCheckInfo);
//             die();

            foreach ($biddinfCheckInfo as $k2 => $v2) {
                if ($v2['needCode']) {
                    $arg = [
                        'needCode' => $v2['needCode']
                    ];
                    $procurementData[] = $this->procurement_model->getByFieldQueryData('id,needCode', $arg, 0);
                }


                foreach ($data[0] as $k3 => $v3) {
                    if ($v3['relevanceId'] == $v2['id']) {
                        $data[0][$k2]['code'] = $v2['code'];
                        $data[0][$k2]['needCode'] = $v2['needCode'];
                        $data[0][$k2]['name'] = $v2['name'];
                        $data[0][$k2]['createTime'] = $v2['createTime'];
                        $data[0][$k2]['validTime'] = $v2['validTime'];
                        $data[0][$k2]['address'] = $v2['address'];
                        $data[0][$k2]['contactMan'] = $v2['contactMan'];
                        $data[0][$k2]['biddingId'] = $v2['biddingId'];
                    }
                }
            }


            foreach ($data[0] as $k4 => $v4) {
                if (isset($procurementData)) {
                    foreach ($procurementData as $k5 => $v5) {
                        if ($v4['needCode'] == $v5['needCode']) {
                            $data[0][$k4]['needId'] = $v5['id'];
                            break;
                        } else {
                            $data[0][$k4]['needId'] = '';

                        }
                    }
                } else {
                    $data[0][$k4]['needId'] = '';

                }

            }


//            echo '<pre>';
//             print_r($data[0]);
//             die();

            $viewData = [
                'list' => $data[0],  //这里得到从数据库中的当页数据
                'totalNum' => $data['total_num'], //这里得到从数据库中的总页数
                'pageNum' => $page_num //每页显示多少条

            ];
        } else {
            $viewData = [
                'list' => $data[0],  //这里得到从数据库中的当页数据
                'totalNum' => $data['total_num'], //这里得到从数据库中的总页数
                'pageNum' => $page_num //每页显示多少条

            ];

        }

//             echo '<pre>';
//             print_r($data);
//             die();

        $this->load->view('/admin/bidding/confirm/list', $viewData);

    }

    //项目定标详情页面
    public function confirmDetail()
    {

        //根据审核表的id再去查询对应的数据.
        $arg = [
            'id' => $_GET['relevanceId']
        ];
        $checkModel['list'] = $this->biddingcheck_model->getByFieldQueryData('*', $arg, 0);

//        print_r($confirmId);
//        die;


        //如果不存在直接跳转到404页面
        if (!$checkModel['list']) {
            redirect('/home/error');
        }


        $checkModel['list']['checkInfo'] = json_decode($checkModel['list']['checkInfo'], true); //审核评分信息
//        $checkModel['list']['endScore'] = count(array_column($checkModel['list']['checkInfo'],'supplierId'));

//        echo '<pre>';
//        print_r($checkModel);
//        die();


        //查询有效的供应商信息
        $checkModel['list']['supplierInfo'] = json_decode($checkModel['list']['supplierInfo'], true);

//    if (count($checkModel['list']['supplierInfo'])) {
//        //取得所有的供应商id,并查询数据
//        $supplierIds = $checkModel['list']['supplierInfo'];
//        foreach ($supplierIds as $k => $v) {
//            $arg2 = [
//                'id' => $v
//            ];
//
//            $supplierData[] = $this->supplier_model->getByFieldQueryData('id,code,name,address', $arg2, 0);
//        }
//        $checkModel['list']['supplierInfo'] = $supplierData;
//    } else {
//        unset($checkModel['list']['supplierInfo']);
//    }

        //根据预选供应商id查询详细信息
        foreach ($checkModel['list']['supplierInfo'] as $k => $v) {
            $arg2 = [
                'id' => $v
            ];

            $supplierInfo[] = $this->supplier_model->getByFieldQueryData('id,code,name,address', $arg2, 0);
        }

//        print_r($supplierInfo);
//        die();


        foreach ($checkModel['list']['supplierInfo'] as $k2 => $v2) {
            $arg2 = [
                'id' => $v2
            ];

            $supplierData[] = $this->supplier_model->getByFieldQueryData('id,code,name,address,offerNum', $arg2, 0);
        }
        $checkInfoData2['supplierInfo'] = $supplierData;
        $checkModel['list']['supplierInfoAll'] = $supplierData;
        $checkModel['list']['supplierInfo'] = $supplierData;

        //只显示上传资料的供应商
        foreach ($checkInfoData2['supplierInfo'] as $k3 => $v3) {
            //根据供应商id查询供应商文件表是否有数据,有数据就显示,没数据就不显示
            $arg3 = [
                'supplierInfo' => $v3['id']
            ];

            $supplierFile[] = $this->waitFile_model->getByFieldQueryData('id', $arg3, 0);
        }

        foreach ($checkInfoData2['supplierInfo'] as $k4 => $v4) {
            foreach ($supplierFile as $k5 => $v5) {
                //查询不到id,则删除当前的供应商信息
                if (!count($v5)) {
                    unset($checkInfoData2['supplierInfo'][$k5]);
                }
            }
        }

        $checkModel['list']['validSupplierNum'] = count($checkInfoData2['supplierInfo']);  //有效的供应商数量


//        $checkModel['list']['checkInfo'] = [
//            0 => [
//                'supplierId' => 143,
//                'checkUser' => '大方',
//                'score' => 65
//            ],
//            1 => [
//                'supplierId' => 143,
//                'checkUser' => '大方',
//                'score' => 65
//            ],
//            2 => [
//                'supplierId' => 140,
//                'checkUser' => '大方',
//                'score' => 65
//            ],
//            6 => [
//                'supplierId' => 140,
//                'checkUser' => '大方',
//                'score' => 65
//            ],
//        ];
        $res = array(); //想要的结果

//        echo '<pre>';
//        print_r($checkModel['list']['checkInfo']);
//        die();


//        print_r($checkModel['list']['checkInfo']);
//        die();

        //循环判断审核信息是否为空,如果为空则就成一个空数组
        foreach ($checkModel['list']['checkInfo'] as $k5 => $v5) {
            if ($v5) {
                $checkModel['list']['newCheckInfo'][$v5['supplierName']][] = $v5;

            } else {
                $checkModel['list']['newCheckInfo'][$v5['supplierName']][] = [];
            }
        }

//        echo '<pre>';
//        print_r($checkModel['list']['newCheckInfo']);
//        die();

//        foreach ($checkModel['list']['checkInfo'] as $k6=>$v6){
//            $count = count($v6['score']);
//            echo $count;
//            $checkModel['list']['checkInfo'][$k6]['mean'] = $v6['score'] / $count;
//        }

        //计算评分的平均分
        foreach ($checkModel['list']['newCheckInfo'] as $k6 => $v6) {
            foreach ($v6 as $k7 => $v7) {
                $arr[$k6][] = $v7['score'];  //提取出分数
            }
        }

        //计算平均值
        foreach ($arr as $k8 => $v8) {
            $sum = array_sum($v8);
            $arr[$k8] = $sum / count($v8); //计算后的平均值  总数/个数
        }

        //根据key相同,加到对应的key中
        foreach ($checkModel['list']['newCheckInfo'] as $k9 => $v9) {
            foreach ($v9 as $k11 => $v11) {
                foreach ($arr as $k10 => $v10) {
                    if ($k9 == $k10) {
                        $checkModel['list']['newCheckInfo'][$k9][$k11]['mean'] = $v10;
                    }
                }
            }


        }


//        echo '<pre>';
//        print_r($checkModel);
//        die();


        $this->load->view('/admin/bidding/confirm/detail', $checkModel);
    }

    /**
     * 根据制定供应商退款,并发送短信的接口
     */
    public function refund()
    {
//        $checkModel = [
//            '66666' => [
//                0 => [
//                    'supplierId' => 161,
//                    'checkUser' => '大方',
//                    'score' => 65
//                ],
//                1 => [
//                    'supplierId' => 161,
//                    'checkUser' => '大方',
//                    'score' => 65
//                ],
//            ],
//            '铭展' => [
//                0 => [
//                    'supplierId' => 142,
//                    'checkUser' => '大方',
//                    'score' => 65
//                ],
//                1 => [
//                    'supplierId' => 142,
//                    'checkUser' => '大方',
//                    'score' => 65
//                ],
//            ],
//
//            '33333' => [
//                0 => [
//                    'supplierId' => 169,
//                    'checkUser' => '大方',
//                    'score' => 65
//                ],
//                1 => [
//                    'supplierId' => 169,
//                    'checkUser' => '大方',
//                    'score' => 65
//                ],
//            ],
//        ];


        $confirm = $_POST['supplierId'];  //确认的供应商id

//        __logInfo('aa',$confirm);

        $checkModel = json_decode($_POST['checkInfoString'], true);  //评分信息

//        $checkModel = [
//            0 => [
//                'supplierId' => '137',
//                'score' => '90',
//                'checkUser' => 'checkUser',
//                'supplierName' => 'supplierName',
//            ],
//            1 => [
//                'supplierId' => '138',
//                'score' => '90',
//                'checkUser' => 'checkUser',
//                'supplierName' => 'supplierName',
//            ],
//        ];


//        foreach ($checkModel as $k3=>$v3){
//            if($v3['supplierId'] == $confirm){
//                unset($checkModel[$k3]);
//            }
//        }
//        sort($checkModel);
//        不管是否定标都退款处理
        $ids = array_column($checkModel, 'supplierId');

//        __logInfo('d',json_encode($ids));

        //根据id去查询供应商待办表, 查询支付订单号和支付时间,金额   ,然后执行退款接口流程

        foreach ($ids as $k => $v) {
            $arg = [
                'supplierInfo' => $v
            ];
            $waitData[] = $this->wait_model->getByFieldQueryData('id,supplierInfo,orderNo,needAmount,orderDatetime', $arg, 0);
        }


        $waitData = array_filter($waitData); //数组去空
//        sort($waitData);
//        print_r($waitData);
//die();
        foreach ($waitData as $k2 => $v2) {
            if ($v2) {

                $arg2 = [
                    'id' => $v2['supplierInfo']
                ];

                $supplierData[] = $this->supplier_model->getByFieldQueryData('id,phone', $arg2, 0);


                __logInfo('aaa', $supplierData[$k2]['phone']);


                //needAmount
                $json = $this->tlRefund($v2['orderNo'], $v2['orderDatetime'], 1);  //接口退款的数据

// $json = $this->refund('NO201708091745345554','20170809174534',1);  //接口退款的数据
                $fomart = json_decode($json, true);  //把json转成数组


                //判断返回值key=8的时候是否存在,存在说明退款成功
                if (isset($fomart[8])) {
//                __logInfo('退款成功',$json);
                    // 退款成功之后，发送短信到供应商手机
                    $pars = array(
                        'name' => '退款三天退回'
                    );

                    $res = $this->sms->run($supplierData[$k2]['phone'], $this->config->item('aliyun_sms')['templateCode']['SMSTemplateCode'], $pars);
                    if ($res) {
                        __logInfo('退款,短信发送成功', $supplierData[$k2]['phone']);

                    } else {
                        __logInfo('退款,短息发送失败', $supplierData[$k2]['phone']);
                    }

                } else {
                    __logInfo('退款失败', $json);
                }

            }


        }


        print_r($supplierData);


    }

    /**
     * 通联退款接口
     * @param string $orderNo 订单号
     * @param string $orderDatetime 订单提交时间
     * @param string $refundAmount 退款金额
     * @return string
     */
    public function tlRefund($orderNo, $orderDatetime, $refundAmount)
    {
//        $serverUrl = $_POST["serverUrl"];//http://ceshi.allinpay.com/gateway/index.do?
//        $serverIP = $_POST["myServerIp"];//ceshi.allinpay.com

        $version = 'v2.3';  //版本号 固定值v2.3
        $signType = '0';
        //根据供应商待办id, 查询商务号id,订单号,订单时间
        $merchantId = '008330148163073';  //商务号id
//        $orderNo = 'NO201708081651264518';   //商户订单号
//        $refundAmount = '1'; //退款金额
//        $orderDatetime = '20170808165126';  //订单时间
//        $orderNo = $orderNom;   //商户订单号
//        $refundAmount = $refundAmount; //退款金额
//        $orderDatetime = $orderDatetime;  //订单时间
        $key = '1234567890';

//        print_r($orderNo);
//        print_r($refundAmount);
//        print_r($orderDatetime);
//        die();

        //组签名原串
        $bufSignSrc = "";
        if ($version != "")
            $bufSignSrc = $bufSignSrc . "version=" . $version . "&";
        if ($signType != "")
            $bufSignSrc = $bufSignSrc . "signType=" . $signType . "&";
        if ($merchantId != "")
            $bufSignSrc = $bufSignSrc . "merchantId=" . $merchantId . "&";
        if ($orderNo != "")
            $bufSignSrc = $bufSignSrc . "orderNo=" . $orderNo . "&";
        if ($refundAmount != "")
            $bufSignSrc = $bufSignSrc . "refundAmount=" . $refundAmount . "&";
        if ($orderDatetime != "")
            $bufSignSrc = $bufSignSrc . "orderDatetime=" . $orderDatetime . "&";
        if ($key != "")
            $bufSignSrc = $bufSignSrc . "key=" . $key;

        //生成签名串
        $signMsg = strtoupper(md5($bufSignSrc));


        $url = 'https://cashier.allinpay.com/gateway/index.do?version=' . $version . '&signType=' . $signType . '&merchantId=' . $merchantId . '&orderNo=' . $orderNo . '&refundAmount=' . $refundAmount . '&orderDatetime=' . $orderDatetime . '&signMsg=' . $signMsg . '';


        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
        $res = curl_exec($ch);

        curl_close($ch);

        //根据&分割成数组,在转成字符串返回
        $jsonString = json_encode(explode('&', $res), JSON_UNESCAPED_UNICODE);

        return $jsonString;

    }


    //删除功能
    public function remove()
    {

        $data = [
            'id' => $this->input->get('id'),
        ];

        //是否会有添加失败的情况?
        $this->bidding_model->remove($data);


        redirect('/admin/bidding/index?page=1');
    }


}



































































